#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //第一种方法label显示图片-QPixmap类
    // QPixmap p01("E:\\Qt\\WorkPace\\obectTimer\\picture\\1.jpg");
    // ui->label->setPixmap(p01);

    //第二种方法label显示图片-QImag类
    QImage image01;
    image01.load("E:\\Qt\\WorkPace\\obectTimer\\picture\\1.jpg");
    ui->label->setPixmap(QPixmap::fromImage(image01));


}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_startButton_clicked()
{
    //开启定时器，返回定时器编号Id
    myTimerId = this->startTimer(TIMEOUT);//

}
void MainWindow :: timerEvent(QTimerEvent *event)
{
    if(event->timerId() != myTimerId)   return;

    QString path("E:\\Qt\\WorkPace\\obectTimer\\picture\\");
    path += QString::number(picID);
    path += ".jpg";
    ui->label_2->setText(path);
    //第一种方法label显示图片-QPixmap类
    // QPixmap pix(path);
    // ui->label->setPixmap(pix);

    //第二种方法label显示图片-QImag类
    QImage image02;
    image02.load(path);
    ui->label->setPixmap(QPixmap::fromImage(image02));


    picID++;//下一张图片
    if(picID > 6) picID=1;

}


void MainWindow::on_stopButton_clicked()
{
    this->killTimer(myTimerId);
}

